package common.customType;

import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Arrays;
import java.util.Objects;

import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.usertype.UserType;

import common.StringUtils;

public class Ctype implements Serializable {

    // mtype 的长度
    private static int TYPE_LENGTH = 16;

    // mtype 实际上就是 char 数组
    private char[] mtype = new char[TYPE_LENGTH];

    // 默认构造函数
    public Ctype() {
        this.mtype = new char[0];
    }

    // 通过构造函数转换为ctype类型
    public Ctype(Object object) {
        String str = String.valueOf(object);
        if (StringUtils.isBlank(str))
            this.mtype = new char[0];
        this.mtype = str.toCharArray();
    }

    public boolean isEmpty() {
        return String.valueOf(this.mtype).replace(" ", "").length() < TYPE_LENGTH;
    }

    public String toString() {
        return String.valueOf(this.mtype);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Ctype ctype = (Ctype) o;
        return Arrays.equals(mtype, ctype.mtype);
    }

    @Override
    public int hashCode() {
        return Arrays.hashCode(mtype);
    }
}
 